class Solution(object):
    def largestInteger(self, num):
        st = []
        while num > 0:
            st.append(num % 10)
            num //= 10
        st.reverse()
        n = len(st)
        for i in range(n):
            for j in range(i + 1, n):
                if st[j] > st[i] and st[i] % 2 == st[j] % 2:
                    st[i], st[j] = st[j], st[i]
        ans = 0
        for num in st:
            ans = 10 * ans + num
        return ans

